/**
 * 
 */
package com.douyu.ocean.recom.platfrom.core.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.douyu.ocean.recom.platform.api.model.entiry.RecomAlgorithm;
import com.douyu.ocean.recom.platfrom.core.dal.mapper.RecomAlgorithmMapper;
import com.douyu.ocean.recom.platfrom.core.service.RecomAlgorithmService;

import tk.mybatis.mapper.entity.Example;

/**
 * @author leiruiqi
 *
 */
@Service("recomAlgorithmService")
public class RecomAlgorithmServiceImpl implements RecomAlgorithmService{

	@Resource
	private RecomAlgorithmMapper  recomAlgorithmMapper;
	
	
	@Override
	public void save(RecomAlgorithm algorithm) {
		recomAlgorithmMapper.insertSelective(algorithm);
	}

	@Override
	public List<RecomAlgorithm> queryAllByStatus(Integer status) {
		Example condition = new Example(RecomAlgorithm.class);
		condition.orderBy("id").asc();
		condition.createCriteria().andEqualTo("status", 0);
		return recomAlgorithmMapper.selectByExample(condition);
	}

	@Override
	public boolean updateById(RecomAlgorithm algorithm) {
		return 1==recomAlgorithmMapper.updateByPrimaryKeySelective(algorithm);
	}

	@Override
	public RecomAlgorithm getByCode(String code) {
		RecomAlgorithm record = new RecomAlgorithm();
		record.setCode(code);
		return recomAlgorithmMapper.selectOne(record);
	}

	@Override
	public RecomAlgorithm getById(Long id) {
		return recomAlgorithmMapper.selectByPrimaryKey(id);
	}

}
